home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / ue3.9-macros < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  10.4 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i031: Interactive speller and other MicroEMACS macros
  5. Message-ID: <8811010650.AA24251@rocky2>
  6. Date: 2 Nov 88 02:23:49 GMT
  7. Sender: allbery@ncoast.UUCP
  8. Reply-To: edf@ROCKY2.ROCKEFELLER.EDU (David MacKenzie)
  9. Lines: 344
  10. Approved: allbery@ncoast.UUCP
  11.  
  12. Posting-number: Volume 5, Issue 31
  13. Submitted-by: "David MacKenzie" <edf@ROCKY2.ROCKEFELLER.EDU>
  14. Archive-name: ue3.9-macros
  15.  
  16. In light of the recent spate of spelling checkers, here is one that
  17. runs under MicroEMACS.  Also, this summer there were discussions about
  18. automatically uncompressing files from GNU EMACS; this posting also
  19. contains macros to do that, as well as some other useful extensions.
  20. The speller depends on the Unix spell program; the other macros
  21. probably need Unix too.  They have been tested under MicroEMACS3.9e.
  22.  
  23. In the ^X! macro, note the line that prints "[End]" and wait for a
  24. keypress; MicroEMACS 3.9e apparently has a bug in that under some OS's,
  25. including Unix, shell-command always waits for a keystroke after
  26. running, while in others, such as MS-DOS, it only does so if it's not
  27. being run from a macro.  Comment that line out if you haven't fixed
  28. that bug for Unix (it just involves adding an "if (clexec == FALSE)
  29. {...}" around the four lines of code in spawn.c that wait for the
  30. keypress).
  31.  
  32. I have the contents of enhance.cmd in my .emacsrc; I load spell.cmd when
  33. I need it with M-x execute-file.
  34.  
  35. David MacKenzie
  36.  
  37. #! /bin/sh
  38. # This is a shell archive.  Remove anything before this line, then unpack
  39. # it by saving it into a file and typing "sh file".  To overwrite existing
  40. # files, type "sh file -c".  You can also feed this as standard input via
  41. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  42. # will see the following message at the end:
  43. #        "End of shell archive."
  44. # Contents:  enhance.cmd spell.cmd
  45. # Wrapped by dave@edfdc  on Fri Sep  9 00:57:35 1988
  46. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  47. if test -f 'enhance.cmd' -a "${1}" != "-c" ; then 
  48.   echo shar: Will not clobber existing file \"'enhance.cmd'\"
  49. else
  50. echo shar: Extracting \"'enhance.cmd'\" \(4045 characters\)
  51. sed "s/^X//" >'enhance.cmd' <<'END_OF_FILE'
  52. X; enhance.cmd
  53. X;
  54. X; MicroEMACS 3.9 macros
  55. X;
  56. X; I.  New bindings
  57. X;    A.  ESC-ESC -> execute command line
  58. X;    B.  ESC-^X  -> execute current buffer
  59. X;    C.  ESC-TAB -> toggle OVERstrike mode
  60. X;    D.  ESC-#   -> filter region through a program
  61. X; II.  Enhancements to existing bindings
  62. X;    B.  ^X! allows response of "!" to repeat previous command
  63. X;    C.  ^X^F, ^X^V, ^X^R, ^X^I, ^X^W, ^X^N expand ~/file properly
  64. X;    D.  ^X^F, ^X^V, ^X^R, ^X^I check if the file exists only in
  65. X;        compressed form (ending with ".Z"), and if so, uncompress it
  66. X;
  67. X; David MacKenzie
  68. X; Latest revision: 09/08/88
  69. X
  70. X
  71. X; Set up ESC-ESC to execute a macro language command from keyboard.
  72. Xbind-to-key execute-command-line M-^[
  73. X
  74. X; Set up ESC-Ctrl-X to execute the current buffer.
  75. X1 store-macro
  76. X    execute-buffer $cbufname
  77. X!endm
  78. Xbind-to-key execute-macro-1 M-^x
  79. X
  80. X; Set up M-TAB to toggle insert/overstrike.
  81. X2 store-macro
  82. X    set $cmode &bxor $cmode 32
  83. X!endm
  84. Xbind-to-key execute-macro-2 M-^I
  85. X
  86. X; Add !! (repeat previous command) capability to shell-command.
  87. X; Activated by a response of "!<Return>".
  88. Xset %prev-cmd "!"
  89. X3 store-macro
  90. X    set %shell-cmd @"!"
  91. X    !if &sequal %shell-cmd "ERROR"  ; Ctrl-G hit.
  92. X        !return
  93. X    !endif
  94. X    !if &sequal %shell-cmd "!"
  95. X        !if &sequal %prev-cmd "!"
  96. X            write-message "[No previous command]"
  97. X            !return
  98. X        !endif
  99. X        ; Echo the command we're repeating for reference, a la csh.
  100. X        write-message &cat "!"  &cat %prev-cmd "~r~n"; CRLF
  101. X        set %shell-cmd %prev-cmd
  102. X    !else
  103. X        set %prev-cmd %shell-cmd
  104. X    !endif
  105. X    shell-command %shell-cmd
  106. X    write-message "[End]"
  107. X    set %rckey >key
  108. X!endm
  109. Xbind-to-key execute-macro-3 ^X!
  110. X
  111. X; If %fname starts with "~/", substitute the value of HOME from environ.
  112. Xstore-procedure tildesub
  113. X    ; ~ is MicroEMACS's escape character so we need to escape it.
  114. X    !if &sequal &left %fname 2 "~~/"
  115. X        set %fname &cat  &env "HOME"  &right %fname &sub &length %fname 1
  116. X    !endif
  117. X!endm
  118. X
  119. X; If %fname exists only as a compressed file, uncompress it first.
  120. Xstore-procedure zcheck
  121. X    !if &and ¬ &exi %fname  &exi &cat %fname ".Z"
  122. X        shell-command &cat "uncompress -v " %fname
  123. X    !endif
  124. X!endm
  125. X
  126. X; Add tilde substitution on file finding, viewing, etc.
  127. X4 store-macro
  128. X    set %fname @"Find file: "
  129. X    !if &sequal %fname "ERROR"  ; Ctrl-G hit.
  130. X        !return
  131. X    !endif
  132. X    run tildesub
  133. X    run zcheck
  134. X    find-file %fname
  135. X!endm
  136. Xbind-to-key execute-macro-4 ^X^F
  137. X
  138. X5 store-macro
  139. X    set %fname @"View file: "
  140. X    !if &sequal %fname "ERROR"
  141. X        !return
  142. X    !endif
  143. X    run tildesub
  144. X    run zcheck
  145. X    view-file %fname
  146. X!endm
  147. Xbind-to-key execute-macro-5 ^X^V
  148. X
  149. X6 store-macro
  150. X    set %fname @"Read file: "
  151. X    !if &sequal %fname "ERROR"
  152. X        !return
  153. X    !endif
  154. X    run tildesub
  155. X    run zcheck
  156. X    read-file %fname
  157. X!endm
  158. Xbind-to-key execute-macro-6 ^X^R
  159. X
  160. X7 store-macro
  161. X    set %fname @"Insert file: "
  162. X    !if &sequal %fname "ERROR"
  163. X        !return
  164. X    !endif
  165. X    run tildesub
  166. X    run zcheck
  167. X    insert-file %fname
  168. X!endm
  169. Xbind-to-key execute-macro-7 ^X^I
  170. X
  171. X8 store-macro
  172. X    set %fname @"Write file: "
  173. X    !if &sequal %fname "ERROR"
  174. X        !return
  175. X    !endif
  176. X    run tildesub
  177. X    write-file %fname
  178. X!endm
  179. Xbind-to-key execute-macro-8 ^X^W
  180. X
  181. X9 store-macro
  182. X    set %fname @"Name: "
  183. X    !if &sequal %fname "ERROR"
  184. X        !return
  185. X    !endif
  186. X    run tildesub
  187. X    change-file-name %fname
  188. X!endm
  189. Xbind-to-key execute-macro-9 ^XN
  190. X
  191. X; Filter the region through an external command.
  192. X10 store-macro
  193. X    set %filt-cmd @"#"
  194. X    !if &or  %sequal %filt-cmd "ERROR"  &sequal %filt-cmd ""
  195. X        !return
  196. X    !endif
  197. X    write-message "[Filtering region]"
  198. X    kill-region
  199. X    2 split-current-window
  200. X    select-buffer "[temp]"
  201. X    yank
  202. X    end-of-file
  203. X    delete-previous-character ; Remove unwanted extra newline.
  204. X    unmark-buffer
  205. X
  206. X    filter-buffer %filt-cmd
  207. X
  208. X    beginning-of-file
  209. X    set-mark
  210. X    end-of-file
  211. X    kill-region
  212. X    unmark-buffer
  213. X    delete-window
  214. X    yank
  215. X    delete-buffer "[temp]"
  216. X    write-message "[Region filtered]"
  217. X!endm
  218. Xbind-to-key execute-macro-10 M-#
  219. END_OF_FILE
  220. if test 4045 -ne `wc -c <'enhance.cmd'`; then
  221.     echo shar: \"'enhance.cmd'\" unpacked with wrong size!
  222. fi
  223. # end of 'enhance.cmd'
  224. fi
  225. if test -f 'spell.cmd' -a "${1}" != "-c" ; then 
  226.   echo shar: Will not clobber existing file \"'spell.cmd'\"
  227. else
  228. echo shar: Extracting \"'spell.cmd'\" \(3560 characters\)
  229. sed "s/^X//" >'spell.cmd' <<'END_OF_FILE'
  230. X; spell.cmd
  231. X;
  232. X; semi-interactive MicroEMACS 3.9 spelling checker
  233. X; Based on the Unix spell command.
  234. X; Activate with M-x run spell-buffer
  235. X;
  236. X; David MacKenzie
  237. X; Latest revision: 08/18/88
  238. X
  239. X
  240. X; These enclose misspelled words.  Change them if you don't like them.
  241. Xset %lmark "<<"
  242. Xset %rmark ">>"
  243. X
  244. Xstore-procedure spell-buffer
  245. X
  246. X    set %savecbuf $cbufname
  247. X    !if &sequal $cfname ""    ; No filename!
  248. X        set $cfname $cbufname ; Make one.
  249. X    !endif
  250. X    set %file $cfname
  251. X    save-file               ; Make sure it's up to date.
  252. X    update-screen
  253. X    
  254. X    set %lfile @"Local word list filename (<Return> = none)? "
  255. X    !if &or  &sequal %lfile "q"  &sequal %lfile "ERROR" ; Ctrl-G
  256. X        write-message "[Spelling correction aborted]"
  257. X        !return
  258. X    !endif
  259. X    !if ¬ &sequal %lfile ""
  260. X        set %lfile &cat  &cat "+" %lfile  " "
  261. X    !endif
  262. X    
  263. X    write-message "[Identifying possible misspellings...]"
  264. X    ; run the command with output to the buffer, "command"
  265. X    pipe-command &cat  &cat "spell " %lfile  %file
  266. X    
  267. X    ; "command" is now the selected buffer
  268. X    delete-window
  269. X    select-buffer %savecbuf
  270. X    
  271. X    !while "TRUE"
  272. X        set %word #command
  273. X    !if &sequal %word "ERROR"
  274. X        !break ; No more mis-spelled words.
  275. X    !endif
  276. X
  277. X        update-screen
  278. X        write-message &cat "Fix `"  &cat %word "' ([y]/n)? "
  279. X        set %yn >key
  280. X        !if &or  &sequal %yn "q"  &equal &ascii %yn 7 ; Ctrl-G
  281. X            write-message "[Spelling correction aborted]"
  282. X        !return
  283. X    !endif
  284. X    !if &or  &sequal %yn "y"  &sequal %yn " "
  285. X            beginning-of-file
  286. X            !while "TRUE"
  287. X                write-message &cat  &cat "[Searching for `" %word  "'...]"
  288. X                !force search-forward %word
  289. X                !if &sequal $status "FALSE"
  290. X                    !break ; No more matches of this word found.
  291. X                !endif
  292. X                run mark-word
  293. X        update-screen ; Let them see the marked word.
  294. X                set %new-word  @&cat  &cat "Replace `" %word  "' with (<Return> to keep)? "
  295. X
  296. X                !if &or  &sequal %new-word "q"  &sequal %new-word "ERROR"
  297. X                    run unmark-word
  298. X                    write-message "[Spelling correction aborted]"
  299. X                    !return
  300. X        !endif
  301. X                !if &sequal %new-word "n" ; Go on to the next wrong word.
  302. X            run unmark-word
  303. X            !break
  304. X        !endif
  305. X                !if &sequal %new-word "p" ; Repeat previous correction.
  306. X                    set %new-word %old-new
  307. X        !endif
  308. X                !if &sequal %new-word ""
  309. X            run unmark-word
  310. X        !else
  311. X                    run replace-word
  312. X                !endif
  313. X                set %old-new %new-word
  314. X        update-screen
  315. X            !endwhile
  316. X    !endif
  317. X    !endwhile
  318. X    write-message "[Spelling correction completed]"
  319. X!endm
  320. X
  321. X; Mark a word with %lmark and %rmark.
  322. X; Assumes point is at the end of the word when called;
  323. X; leaves point after %rmark.
  324. Xstore-procedure mark-word
  325. X    insert-string %rmark
  326. X    set-mark
  327. X    previous-word
  328. X    insert-string %lmark
  329. X!endm
  330. X
  331. X; Remove the mark.
  332. X; Assumes point is where mark-word left it, after %lmark.
  333. X; Leaves point after the word.
  334. Xstore-procedure unmark-word
  335. X    &len %lmark delete-previous-character ; Nuke %lmark.
  336. X    exchange-point-and-mark ; Move past %rmark.
  337. X    &len %rmark delete-previous-character ; Nuke %rmark
  338. X!endm
  339. X
  340. X; Replace the marked word with %new-word.
  341. X; Called instead of unmark-word.
  342. X; Leaves point after the word.
  343. Xstore-procedure replace-word
  344. X    &len %lmark delete-previous-character ; Nuke %lmark.
  345. X    kill-region ; Nuke word and %rmark.
  346. X    insert-string %new-word
  347. X!endm
  348. END_OF_FILE
  349. if test 3560 -ne `wc -c <'spell.cmd'`; then
  350.     echo shar: \"'spell.cmd'\" unpacked with wrong size!
  351. fi
  352. # end of 'spell.cmd'
  353. fi
  354. echo shar: End of shell archive.
  355. exit 0
  356.